import zhenzismsclient as smsclient
import random

from flask import session
import json


# 发送短信验证码的类
def sendMessageFunction(phoneNumber):
    # 生成四位数的随机验证码
    code = ''
    for num in range(1, 5):
        code = code + str(random.randint(0, 9))
    print(code)
    session['code'] = code
    # 将AppId和AppSecret复制粘贴过来
    client = smsclient.ZhenziSmsClient("https://sms_developer.zhenzikj.com", 111134,
                                       "MWNiNDQyMWMtODk5ZS00YjExLWE5NjMtNDA3YjQxNzcxZGE5")
    # 发送短信需要的参数
    params = {}
    params['number'] = phoneNumber
    params['templateId'] = '8536'
    params['templateParams'] = [code, '5分钟']
    print(client.send(params))
    # 查看余额
    result = client.balance()
    print('result ::::' + result)
    return 0


def sendDangerMessage(phoneNumber, type):
    # 将AppId和AppSecret复制粘贴过来
    client = smsclient.ZhenziSmsClient("https://sms_developer.zhenzikj.com", 111134,
                                       "MWNiNDQyMWMtODk5ZS00YjExLWE5NjMtNDA3YjQxNzcxZGE5")
    # 发送短信需要的参数
    params = {}
    params['number'] = phoneNumber
    params['templateId'] = '5002'
    params['templateParams'] = [type]
    print(client.send(params))
    # 查看余额
    result = client.balance()
    print(result)

    return 0
